package com.huowei.htzy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.huowei.htzy.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;


public class GuideActivity extends AppCompatActivity {

    @InjectView(R.id.guide_view_pager)
    ViewPager guideViewPager;
    private List<View> views = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        ButterKnife.inject(this);
        //初始化数据
        initData();
        //设置适配器
        initAdapter();
    }

    private void initAdapter() {
        PagerAdapter adapter = new PagerAdapter() {
            @Override
            public int getCount() {
                return views.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                container.addView(views.get(position));
                return views.get(position);
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView((View) object);
            }
        };
        guideViewPager.setAdapter(adapter);
    }

    private void initData() {
        views.clear();
        LayoutInflater inflater = LayoutInflater.from(this);
        View v1 = inflater.inflate(R.layout.guide_item1, null);
        View v2 = inflater.inflate(R.layout.guide_item2, null);
        View v3 = inflater.inflate(R.layout.guide_item3, null);
        Button bt = (Button) v3.findViewById(R.id.guide_bt);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(GuideActivity.this,HomeActivity.class));
                finish();
            }
        });
        views.add(v1);
        views.add(v2);
        views.add(v3);
    }

}
